<template>
  <div class="search">
    <k-form-build ref="dynamicForm" :value="formJson"/>
  </div>
</template>
<script>
  import api from './js/api'

  export default {
    name: 'StartProcessForm',
    props: {},
    data() {
      return {
        refs: this.$refs,
        api: Object.assign(api, this.api),
        loaded: false,//是否加载完成
        formJson: {},
        processDefinition: {},
        startFormVisible: false,
        formItem: this.getFormItem()
      }
    },
    methods: {
      getFormItem() {
        return {
          processId: ''
        }
      },
      //表单赋值
      setData(data) {
        this.formItem = this.getFormItem()
        if (data && data.formKey) {
          this.processDefinition = data
          this.http.get(this, {
            url: this.api.processDefinition.renderedStartForm,
            params: {
              processDefinitionId: data.id
            },
            success: function(me, data) {
              console.info(data.renderedStartForm)
              me.formJson = JSON.parse(data.renderedStartForm)
              me.startFormVisible = true
            }
          })
        }
      },
      //提交表单
      handleSubmit(callback) {
        this.$refs['dynamicForm'].getData().then(formData => {
          let processInstanceFormData = JSON.stringify(formData)
          let realValues = Object.assign({processInstanceFormData}, formData)
          let postData = {
            handlerName: 'testStartProcessHandler',
            formMap: realValues,
            processDefinitionId: this.processDefinition.id
          }
          this.http.saveOrUpdate(this, {
            api: api.processInstance.start,
            requestBody: true,
            data: postData,
            success: function(me, data) {

            }
          })
        })
      }
    },
    created() {
    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
